package com.xszx.servlet;

import com.xszx.beans.Goods;
import com.xszx.dao.GoodsDao;
import com.xszx.dao.impl.GoodsDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/GoShopServlet")
public class GoShopServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");

        int id = Integer.parseInt(req.getParameter("id"));
        String username = req.getSession().getAttribute("username").toString();

        GoodsDao goodsDao = new GoodsDaoImpl();
        Goods goods = goodsDao.getGoods(id);

        req.setAttribute("shopGoods", goods);
        req.setAttribute("username", username);

        req.getRequestDispatcher("my_likafu/shop.jsp").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
